package com.zhuiyun.pm.client.action.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhuiyun.pm.client.action.entity.GoodsEarnestMoneyEntity;
import com.zhuiyun.pm.client.action.entity.GoodsEntity;
import com.zhuiyun.pm.client.action.service.AuctionService;
import com.zhuiyun.pm.config.CommonResult;
import com.zhuiyun.pm.page.PageRequest;
import com.zhuiyun.pm.utils.PrimaryKeyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @ClassName AuctionController
 * @Description TODO 拍卖 controller层
 * @Author 赵笛
 * @Date 2023/3/14 8:46
 **/
@RestController
@CrossOrigin
@RequestMapping("/client/auction")
public class AuctionController {
    @Autowired
    AuctionService auctionService;
    /**
    * @Author 赵笛
    * @Description TODO 根据（地址）（状态）查询竞品信息列表
    * @Date 2023/3/14 14:03
    * @Return com.zhuiyun.pm.config.CommonResult
    * @param address
    * @param status
    * @param pageRequest
    */
    @GetMapping("/getGoodsList")
    public CommonResult getGoodsList(String goodsName,String address, String status, PageRequest pageRequest){
        //设置分页信息
        PageHelper.startPage(pageRequest.getPageNum(),pageRequest.getPageSize());
        //调用分页查询的方法
        List<GoodsEntity> goodsList=auctionService.getGoodsList(goodsName,address,status,pageRequest);
        //创建分页对象
        PageInfo<GoodsEntity> goodsPageInfo=new PageInfo<>(goodsList);
        return CommonResult.ok(goodsPageInfo);
    }
    /**
    * @Author 赵笛
    * @Description TODO 根据当前登录用户id查询用户与商品的保证金信息
    * @Date 2023/3/14 20:42
    * @Return com.zhuiyun.pm.config.CommonResult
    * @param userId
    */
    @GetMapping("/getGoodsEarnestMoneyByUserId")
    public CommonResult getGoodsEarnestMoneyByUserId(Integer userId,Integer goodsId){
        return auctionService.getGoodsEarnestMoneyByUserId(userId,goodsId);
    }
    /**
     * @Author 赵笛
     * @Description TODO 根据当前登录用户id查询用户与商品的保证金信息
     * @Date 2023/3/14 20:42
     * @Return com.zhuiyun.pm.config.CommonResult
     * @param goodsId
     */
    @GetMapping("/getGoodsEarnestMoneyCount")
    public CommonResult getGoodsEarnestMoneyCount(Integer goodsId){
        return auctionService.getGoodsEarnestMoneyCount(goodsId);
    }
    /**
     * @Author 梁栋
     * @Description TODO app查询审核状态5的goods
     * @Date 2023/3/16 15:42
     * @Return com.zhuiyun.pm.config.CommonResult
     * @Param [java.lang.String]
     */
    @GetMapping("/getGoodsListNotPage")
    public CommonResult getGoodsListNotPage(String status){
        List<GoodsEntity> goodsList=auctionService.getGoodsListNotPage(status);
        return CommonResult.ok(goodsList);
    }

    /**
     * @Author 梁栋
     * @Description TODO 根据用户id分页查询商品列表
     * @Date 2023/3/16 15:42
     * @Return com.zhuiyun.pm.config.CommonResult
     * @Param [java.lang.String]
     */
    @GetMapping("/getGoodsByUserIdLimit6")
    public  CommonResult getGoodsByUserIdLimit6(Integer userId){
        return CommonResult.ok(auctionService.getGoodsByUserIdLimit6(userId));
    }

    /**
     * @Author 赵笛
     * @Description TODO 根据用户id查询当前用户
     * @Date 2023/3/23 15:00
     * @Return com.zhuiyun.pm.config.CommonResult
     * @param goodsId
     */
    @GetMapping("/getGoodsById")
    public CommonResult getGoodsById(Integer goodsId){
        return auctionService.getGoodsById(goodsId);
    }

    /**
     * @Author 高
     * @Description app查询拍卖类型
     * @Date 2023/3/23 9:50
     * @Return com.zhuiyun.pm.config.CommonResult
     * @Param
     */
    @GetMapping("/getGoodsListType")
    public CommonResult getGoodsListType(String auctionType){
        List<GoodsEntity> goodsList=auctionService.getGoodsListType(auctionType);
        return CommonResult.ok(goodsList);
    }

    /**
    * @Author 赵笛
    * @Description TODO 修改保证金状态
    * @Date 2023/3/28 11:24
    * @Return com.zhuiyun.pm.config.CommonResult
    * @param goodsEarnestMoneyEntity
    */
    @PutMapping("updateEarnestMoneyStatus")
    public CommonResult updateEarnestMoneyStatus(@RequestBody GoodsEarnestMoneyEntity goodsEarnestMoneyEntity){
        return auctionService.updateEarnestMoneyStatus(goodsEarnestMoneyEntity);
    }

    /**
    * @Author 赵笛
    * @Description TODO 生成当前用户的缴纳保证金状态
    * @Date 2023/3/27 18:52
    * @Return com.zhuiyun.pm.config.CommonResult
    * @param goodsEarnestMoneyEntity
    */
    @PostMapping("/generateGoodsEarnestMoney")
    public CommonResult generateGoodsEarnestMoney(@RequestBody GoodsEarnestMoneyEntity goodsEarnestMoneyEntity){
        return auctionService.generateGoodsEarnestMoney(goodsEarnestMoneyEntity);
    }

    /**
    * @Author 赵笛
    * @Description TODO 根据当前登录用户（卖家）和审核状态查询竞品列表
    * @Date 2023/3/29 19:08
    * @Return com.zhuiyun.pm.config.CommonResult
    * @param sellerId
    * @param checkStatus
    * @param goodsName
    */
    @GetMapping("/getGoodsListBySellerIdAndStatus")
    public CommonResult getGoodsListBySellerIdAndStatus(Integer sellerId,Integer checkStatus,String goodsName){
        return auctionService.getGoodsListBySellerIdAndStatus(sellerId,checkStatus,goodsName);
    }

    /**
    * @Author 赵笛
    * @Description TODO 根据id删除竞品
    * @Date 2023/3/30 16:50
    * @Return com.zhuiyun.pm.config.CommonResult
    * @param goodsId
    */
    @DeleteMapping("/deleteGoodsById")
    public CommonResult deleteGoodsById(Integer goodsId){
        return auctionService.deleteGoodsById(goodsId);
    }
}
